package com.talos.ums.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.StringUtils;

@Getter
@AllArgsConstructor
public enum ResourceTypeEnum {

    MENU("MENU", "菜单"),
    DIRECTORY("DIRECTORY", "目录"),
    BUTTON("BUTTON", "按钮");

    private final String code;
    private final String name;

    public static ResourceTypeEnum codeOf(String code) {
        if (!StringUtils.hasLength(code)) {
            return null;
        }

        for (ResourceTypeEnum resourceTypeEnum : ResourceTypeEnum.values()) {
            if (code.equals(resourceTypeEnum.getCode())) {
                return resourceTypeEnum;
            }
        }

        throw new IllegalArgumentException("资源类型有误");
    }
}
